﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace OpenWeb
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {

            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //AuthConfig.RegisterAuth();
            //WebApiConfig.Register(GlobalConfiguration.Configuration);

            //ConfigureContainer();// repository

            //new AutoMapperConfiguration().Configure(); //mapper
            //Mapper.AssertConfigurationIsValid();



            Database.SetInitializer<OpenWeb.DAL.Models.OpenWebDBContext>(
          new System.Data.Entity.DropCreateDatabaseAlways<OpenWeb.DAL.Models.OpenWebDBContext>());

            using (var db = new OpenWeb.DAL.Models.OpenWebDBContext())
            {
                db.Database.Initialize(true);
                //db.Database.Create();
            }


         
        }//fM


        private void ConfigureContainer()
        {
            //_container = new UnityContainer()
            //        .RegisterType<IContactsService, ContactService>()
            //    //.RegisterType<IFileService, FileService>()
            //        .RegisterType<IDocumentRepository, DocumentRepository>();


            //.RegisterType<IDocumentService, DocumentService>(new ContainerControlledLifetimeManager())
            //.RegisterType<IFileService, FileService>()
            //.RegisterType<IDocumentRepository, DocumentRepository>()



            //.RegisterType<IFileRepository, FileRepository>()
            //.RegisterType<IRepositoryContext, DmsRepositoryContext>()
            //.RegisterType<IFormsAuthenticationService, FormsAuthenticationService>()
            //.RegisterType<IMembershipService, AccountMembershipService>();

            //Set for Controller Factory
            IControllerFactory controllerFactory = new UnityControllerFactory(_container);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);

        }







    }
}